package com.phpxiu.app.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.phpxiu.app.kkylive.R;
import com.phpxiu.app.model.list.LogRecord;

import java.util.ArrayList;
import java.util.List;

/**
 * @file
 * @brief 显示的debug日志列表适配器
 * @author 吴金洲
 * @note 显示的debug日志列表适配器
 *
 */
public class LogListAdapter extends android.widget.BaseAdapter {
    private List<LogRecord> logs=new ArrayList<LogRecord>();
    private LayoutInflater mInflater;

    public LogListAdapter(Context context) {
        mInflater=LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return logs.size();
    }

    @Override
    public Object getItem(int position) {
        return logs.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if(convertView==null){
            convertView=mInflater.inflate(R.layout.log_list_item_view,null);
        }
        TextView tagView=(TextView)convertView.findViewById(R.id.tag_view);
        tagView.setText(logs.get(position).getTag());
        TextView contentView=(TextView)convertView.findViewById(R.id.log_content_view);
        contentView.setText(logs.get(position).getLog());
        return convertView;
    }

    public void addRecord(LogRecord log){
        logs.add(0,log);
        notifyDataSetChanged();
    }
}
